/**
 * 主页js
 */

if(location.href=="http://czt.jl.gov.cn/" || location.href=="http://czt.jl.gov.cn/index.html"){
//首页

	$("select[name='select5']").attr("title","全国财政系统");
	$("select[name='select']").attr("title","本省财政系统");
	$("select[name='select2']").attr("title","省政府及省直部门");
	$("select[name='select3']").attr("title","财经相关网站");
	
//页面中间有个flash，焦点切换经过时，有的版本ie会发生跳点
	$("#content>table:eq(4) object").attr("tabindex","-1");
	
	//object上面的一个a
	_EsdDynamicTransformationScript.esdObjectPrev = $("body > table:nth-child(13) > tbody > tr > td:nth-child(2) > table:nth-child(4) > tbody > tr:nth-child(2) > td > table > tbody > tr > td > table > tbody > tr:nth-child(7) > td:nth-child(2) > span > a");
	//object下面的一个a
	_EsdDynamicTransformationScript.esdObjectNext = $("body > table:nth-child(13) > tbody > tr > td:nth-child(2) > table:nth-child(6) > tbody > tr > td:nth-child(1) > table > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(3) > span > a");
	
	_EsdDynamicTransformationScript.esdObjectPrev.focus(function (e) {
		$(this).bind("keydown.keydownsss_0", function (e) {
			if(e.shiftKey&&e.keyCode==9){

			}else if(e.keyCode == 9) {
				_EsdDynamicTransformationScript.esdObjectNext.focus();
				return false;
			}
		});
	});
	_EsdDynamicTransformationScript.esdObjectPrev.blur(function () {
		$(this).unbind("keydown.keydownsss_0");
	});
	
	_EsdDynamicTransformationScript.esdObjectNext.focus(function (e) {
		$(this).bind("keydown.keydownsss_1", function (e) {
			if(e.shiftKey&&e.keyCode==9){
				_EsdDynamicTransformationScript.esdObjectPrev.focus();
				return false;
			}else if (e.keyCode == 9) {
				
			}
		});
	});
	_EsdDynamicTransformationScript.esdObjectNext.blur(function () {
		$(this).unbind("keydown.keydownsss_1");
	});
	
	
	
// 将iframe所包含的a链接数 第一个a元素 最后一个a元素赋值给第一个参数的js对象
_EsdDynamicTransformationScript.getIframeInfos = function(jsObj,iframeObj){
	jsObj.aLink_num = iframeObj.contentWindow.document.getElementsByTagName("a").length;
	jsObj.first_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[0];
	jsObj.last_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[jsObj.aLink_num-1];
	jsObj.self = iframeObj;
};

// 声明iframe操作对象
_EsdDynamicTransformationScript.iframe1 = {};
_EsdDynamicTransformationScript.iframe2 = {};

//通过方法赋值   
_EsdDynamicTransformationScript.iframeElement1 = document.getElementsByTagName("iframe")[3];   // 需要修改 这里的iframe获取
_EsdDynamicTransformationScript.iframeElement2 = document.getElementsByTagName("iframe")[4];   // 需要修改 这里的iframe获取


//选项卡标签 jquery对象
_EsdDynamicTransformationScript.iframeTab1 = $("#tab2_t1 a");  // 需要修改 这里的tab获取
_EsdDynamicTransformationScript.iframeTab2 = $("#tab2_t2 a");  // 需要修改 这里的tab获取


// 判断iframe是否有效
if((_EsdDynamicTransformationScript.iframeElement1!=undefined) && (_EsdDynamicTransformationScript.iframeElement2!=undefined)){

	// 当iframe都加载完毕后执行代码 使用setInterval
	_EsdDynamicTransformationScript.iframeInterval = setInterval(function(){
		
		if((_EsdDynamicTransformationScript.iframeElement1.contentWindow.document.getElementsByTagName("a")[0]!=undefined) 
				&& (_EsdDynamicTransformationScript.iframeElement2.contentWindow.document.getElementsByTagName("a")[0]!=undefined) ){
			clearInterval(_EsdDynamicTransformationScript.iframeInterval);
			
			//通过方法赋值   
			_EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe1,_EsdDynamicTransformationScript.iframeElement1);  
			_EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe2,_EsdDynamicTransformationScript.iframeElement2); 

		//第一个标签 切换
		_EsdDynamicTransformationScript.iframeTab1.focus(function (e) {
			console.log("tab1获取到焦点");
			e = $(this).mouseover();
			$(this).bind("keydown.iframeKeydown_1", function (e) {
				if (e.shiftKey && e.keyCode == 9) {
					console.log("tab1向回切换");
					_EsdDynamicTransformationScript.iframeTab1.trigger("blur");
					$("select[name='select3']").focus();
					return false;
				} else if (e.keyCode == 9) {
					console.log("tab1继续切换到iframe上");
					_EsdDynamicTransformationScript.iframeTab1.trigger("blur");
					$(_EsdDynamicTransformationScript.iframe1.self).focus();
					console.log(document.activeElement);
					return false;
				}
			});
		});
		_EsdDynamicTransformationScript.iframeTab1.blur(function () {
			$(this).unbind("keydown.iframeKeydown_1");
		});

		// 第一个标签的第一个链接
		$(_EsdDynamicTransformationScript.iframe1.first_aLink).focus(function () {
			console.log("第一个iframe的第一条获得焦点");
			$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
				if (e.shiftKey && e.keyCode == 9) {
					console.log("第一个iframe的第一条向上切换");
					$(this).trigger("blur");
					_EsdDynamicTransformationScript.iframeTab1.focus();
					return false;
				} else if (e.keyCode == 9) {
					console.log("第一个iframe的第一条继续切换");
				}
			});
		});
		$(_EsdDynamicTransformationScript.iframe1.first_aLink).blur(function () {
			$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
		});

		// 第一个标签的最后一个链接
		$(_EsdDynamicTransformationScript.iframe1.last_aLink).focus(function () {
			console.log("第一个iframe的最后一条获得焦点");
			$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
				if (e.shiftKey && e.keyCode == 9) {
					console.log("第一个iframe的最后一条向上切换");
				} else if (e.keyCode == 9) {
					console.log("第一个iframe的最后一条继续切换 到下一个标签");
					 $(this).trigger("blur");
					_EsdDynamicTransformationScript.iframeTab2.focus();
					return false;
				}
			});
		});
		$(_EsdDynamicTransformationScript.iframe1.last_aLink).blur(function () {
			$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
		});


		//第二个标签切换
		_EsdDynamicTransformationScript.iframeTab2.focus(function (e) {
			console.log("tab2获取到焦点");
			e = $(this).mouseover();
			$(this).bind("keydown.iframeKeydown_2", function (e) {
				if (e.shiftKey && e.keyCode == 9) {
					console.log("第二个标签向回切换 到第一个标签的最后一条");
					_EsdDynamicTransformationScript.iframeTab2.trigger("blur");
					_EsdDynamicTransformationScript.iframeTab1.mouseover();
					$(_EsdDynamicTransformationScript.iframe1.last_aLink).focus();
					return false;
				} else if (e.keyCode == 9) {
					_EsdDynamicTransformationScript.iframeTab2.trigger("blur");
					$(_EsdDynamicTransformationScript.iframe2.self).focus();
					console.log(document.activeElement);
					return false;
				}
			});

		});
		_EsdDynamicTransformationScript.iframeTab2.blur(function () {
			$(this).unbind("keydown.iframeKeydown_2");
		});

		}
	}, 500);

}
  
	

//首页结束	
}


